package com.example.demo.controller;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.demo.model.ExamRule;
import com.example.demo.model.ResposeModel;
import com.example.demo.modelApi.ExamTkCnApi;
import com.example.demo.service.CourseOfflineService;
import com.example.demo.service.ExamRuleService;
import com.example.demo.service.ExamTkCnApiService;

/*线上课程*/
@Controller
@RequestMapping("/api/exam")
public class ExamController {
	private Logger log = LoggerFactory.getLogger(CustomerController.class);
	
	@Autowired
	private ExamRuleService examRuleService;
	@Autowired
	private ExamTkCnApiService examTkCnApiService;
	
	/* 获取模拟考试试题 */
	@RequestMapping("/getExam/car/{car}/course/{course}/language/{language}")
	@ResponseBody
	public ResposeModel getExam(@PathVariable("car") Integer car,
								@PathVariable("course") Integer course,
								@PathVariable("language") Integer language) {
		// 根据驾照类型出题规则
		List<ExamRule> rule = examRuleService.selectExamRule(car, course);
		// 根据出题规则获取试题
		List<ExamTkCnApi> examTkCnApis = new ArrayList<>();
		if(1 == language) {
			for(int i = 0; i < rule.size(); i++) {
				Integer type = rule.get(i).getType();
				Integer single = rule.get(i).getSingle();
				Integer doubles = rule.get(i).getDoubles();
				Integer opinion = rule.get(i).getOpinion();
				List<ExamTkCnApi> examTkCnApi = examTkCnApiService.selectExamTkCn(car, course,type,single,doubles,opinion);
				examTkCnApis.addAll(examTkCnApi);
				System.out.println(examTkCnApis.size());
			}
		}
		
		ResposeModel res = new ResposeModel();
		try {
			res.setData(examTkCnApis);
			
		} catch (Exception e) {
			log.info("getExam:"+e.toString());
			res.setStatus("0");
			res.setMsg("获取数据出错");
		}

		return res;
	}
}
